package com.ruoyi.coffee.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.coffee.domain.Attributes;
import com.ruoyi.coffee.service.IAttributesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 咖啡属性Controller
 * 
 * @author dxj
 * @date 2025-01-05
 */
@RestController
@RequestMapping("/coffee/attributes")
public class AttributesController extends BaseController
{
    @Autowired
    private IAttributesService attributesService;

    /**
     * 查询咖啡属性列表
     */
    @PreAuthorize("@ss.hasPermi('coffee:attributes:list')")
    @GetMapping("/list")
    public TableDataInfo list(Attributes attributes)
    {
        startPage();
        List<Attributes> list = attributesService.selectAttributesList(attributes);
        return getDataTable(list);
    }

    /**
     * 导出咖啡属性列表
     */
    @PreAuthorize("@ss.hasPermi('coffee:attributes:export')")
    @Log(title = "咖啡属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Attributes attributes)
    {
        List<Attributes> list = attributesService.selectAttributesList(attributes);
        ExcelUtil<Attributes> util = new ExcelUtil<Attributes>(Attributes.class);
        util.exportExcel(response, list, "咖啡属性数据");
    }

    /**
     * 获取咖啡属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('coffee:attributes:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(attributesService.selectAttributesById(id));
    }

    /**
     * 新增咖啡属性
     */
    @PreAuthorize("@ss.hasPermi('coffee:attributes:add')")
    @Log(title = "咖啡属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Attributes attributes)
    {
        return toAjax(attributesService.insertAttributes(attributes));
    }

    /**
     * 修改咖啡属性
     */
    @PreAuthorize("@ss.hasPermi('coffee:attributes:edit')")
    @Log(title = "咖啡属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Attributes attributes)
    {
        return toAjax(attributesService.updateAttributes(attributes));
    }

    /**
     * 删除咖啡属性
     */
    @PreAuthorize("@ss.hasPermi('coffee:attributes:remove')")
    @Log(title = "咖啡属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attributesService.deleteAttributesByIds(ids));
    }
}
